/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ctrl.jeu;

import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Image;
import java.io.Serializable;
import java.util.ArrayList;
import javax.swing.ImageIcon;

/**
 *
 * @author Willy KONGUEM
 */
public class Mise implements Comparable<Mise>, Serializable{
    private Place places; // joueur concerné par la mise
    private float MontantTotal; // montant total de la mise
    private boolean FirstDisplay;

    public Mise(Place places, float MontantTotal) {
        this.places = places;
        this.MontantTotal = MontantTotal;
    }
    
    public float getMontantTotal() {
        return MontantTotal;
    }

    public void setMontantTotal(float MontantTotal) {
        this.MontantTotal = MontantTotal;
    }

    public Place getPlaces() {
        return places;
    }

    public void setPlaces(Place places) {
        this.places = places;
    }

    public int compareTo(Mise o) {
        return Math.round(this.MontantTotal-o.getMontantTotal());
    }

    public void Affiche(Container cont, int x, int y)
    {
        Graphics g=cont.getGraphics();
        ImageIcon imgi=new javax.swing.ImageIcon(getClass().getResource("/img/J_Noir.png"));
        Image image = imgi.getImage();
        g.drawImage(image, x, y,30,30,cont);
        /*g.setColor(Color.BLUE);
        g.fillOval(x, y,30,30);*/
        g.setColor(Color.BLACK);
        g.drawString(""+getMontantTotal(), x+10,y-7);

    }

    public void Deplace(Container cont,int xi, int yi,int xf, int yf)
    {
        // on deternime le coeff la droite est sous la forme : y=ax+b

        float a=(yf-yi)/(xf-xi);
        float b=yi-(a*xi);
        
        boolean p1=yi<yf;
        boolean p2=yi<yf;
        while(!(!p2||p1)&&(!p1||p2))
        {
            Affiche(cont,xi,yi);
         
            cont.repaint();
            try { Thread.sleep(100); } catch(Exception e) {}
            // modification de xi et yi
            xi+=3;
            yi=(int)((a*xi)+b);
            p2=yi<yf;
        }
    }

    public boolean isFirstDisplay() {
        return FirstDisplay;
    }

    public void setFirstDisplay(boolean FirstDisplay) {
        this.FirstDisplay = FirstDisplay;
    }

    
    public static float Total(ArrayList<Mise> m )
    {
        float s=0;
        for(int i=0;i<m.size();i++) s+=m.get(i).getMontantTotal();
        return s;
    }

    @Override
    public String toString() {
        return "[Mise]:"+getMontantTotal();
    }

    public static boolean isComplete(ArrayList<Mise> LstM,ArrayList<Place> LstP)
    {
        float k=-1;
        //System.out.println("LstM= "+LstM+"   LstP= "+LstP);
        for(int i=0;i<LstM.size();i++)
        {
            Mise p=LstM.get(i);
            if(LstP.contains(p.getPlaces()))
            {
                if(k==-1) k=p.getMontantTotal();
                else if(p.getMontantTotal()!=k) return false;

            }
        }
        return true;
    }

    
}
